<?php

$profileId=$_SESSION['profileid'];
$trackingcode=$_SESSION['trackingcode'];
//echo $trackingcode;
//$table = "";
$PAUParams = array(
      'dimensions' => 'ga:dimension1'
		);
$resultsPAU = $analytics->data_ga->get(
       'ga:' . $profileId,
       '2014-12-29',
       '2015-01-03',
	   'ga:pageviews',
       $PAUParams
	   );
$conn = mysql_connect('localhost', 'root', '');
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';

mysql_select_db('tuts_rest', $conn);
	echo '<div class = "container" >';

	echo '<table class="table table-hover">';


	echo '<tr>';
	
	echo '<th align="center">IDFacebook</th>';
	echo '<th align="center">Nama Audience</th>';
	echo '<th align="center">Page View</th>';

	echo '</tr>';	   
	foreach ($resultsPAU->getRows() as $row) {
	$sql = 'SELECT * FROM audience where idanalytics ="'.$trackingcode.'" AND idaudience = "'.$row[0].'"';

	$resultquery = mysql_query($sql);
	if($resultquery === FALSE) {
	die(mysql_error()); // TODO: better error handling
	}

	while($audience = mysql_fetch_array($resultquery)) {
	

	echo '<tr>';
	echo '<td align="left">'.$audience['idfacebook'].'</td>';
	echo '<td align="left">'.$audience['username'].'</td>';
	echo '<td align="left">'.$row[1].'</td>';

	//echo '<td align="left">'.$row[1].'</td>';
	echo '</tr>';	
	
		}
		
	
	}

	echo '</table>';
	echo '</div>';	
 
